﻿using System.Collections.Specialized;
using System.Globalization;
using Skybrud.Social.Instagram.Responses;

namespace Skybrud.Social.Instagram.Endpoints {

    public class InstagramMediaSearchOptions {
        public double Latitude { get; set; }
        public double Longitude { get; set; }
        public int Distance { get; set; }
    }
    
    public class InstagramMediaEndpoint {

        protected InstagramService Service;

        internal InstagramMediaEndpoint(InstagramService service) {
            Service = service;
        }

        public string SearchAsRawJson(double latitude, double longitude) {

            // Declare the query string
            NameValueCollection qs = new NameValueCollection {
                {"access_token", Service.AccessToken},
                {"lat", latitude.ToString(CultureInfo.InvariantCulture)},
                {"lng", longitude.ToString(CultureInfo.InvariantCulture)}
            };

            // Perform the call to the API
            return SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://api.instagram.com/v1/media/search", qs);

        }

        public InstagramMediaResponse Search(double latitude, double longitude) {
            return InstagramMediaResponse.ParseJson(SearchAsRawJson(latitude, longitude));
        }
    
    }

}
